<?php

use Biz\service\springHomeDecActivity\ActivityService;
use Biz\service\springHomeDecActivity\LuckyCharmTicketService;

class UserLuckyTicketAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;

    const VALIDATOR_TOAST_DEBUG = true;

    const PERPAGE_COUNT = 20;

    //参数校验-规则
    public const VALIDATOR_RULES = [
        'page' => 'require|integer',
    ];

    //参数校验-自定义消息
    public const VALIDATOR_MSG = [
        'page.require' => '参数错误',
    ];

    public function main()
    {
        $page = $this->params['page'] ?? 1;
        $pageSize = self::PERPAGE_COUNT;
        $userLuckyCharmTickets = [];
        $totalCount = LuckyCharmTicketService::userTicketsCount($this->uid);
        $isOver = $page * $pageSize >= $totalCount ? 1 : 0;
        $result = LuckyCharmTicketService::exchangedTickets($this->uid, $page, self::PERPAGE_COUNT);
        if ($result && is_array($result)) {
            $userLuckyCharmTickets = $result;
        }
        $data = [
            'is_over' => $isOver,
            'total_count' => $totalCount,
            'list' => $userLuckyCharmTickets,
            'activity_info' => ActivityService::activityInfo(),
        ];
        $this->setSuccess($data);
    }
}